using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ResxHelper.Forms
{
    public partial class FrmMissingWords : Form
    {
        private Dictionary<string, string[]> _results; 
        public FrmMissingWords()
        {
            InitializeComponent();
        }

        public FrmMissingWords(Dictionary<string, string[]> results) : this()
        {
            _results = results;
            LoadResults(_results);
        }

        public void LoadResults(Dictionary<string, string[]> results)
        {
            var resultList = results.Select(result => new KeyValuePair<string, string>(result.Key, result.Key)).ToList();

            // load listbox
            lbFiles.DataSource = resultList;
            lbFiles.DisplayMember = "Key";
            lbFiles.ValueMember = "Value";
        }

        public void ShowMissingWords()
        {
            txtOutput.Clear();
            if ((lbFiles.SelectedValue is KeyValuePair<string, string>)) return;

            var selection = lbFiles.SelectedValue.ToString();
            var missingWords = _results[selection];
            foreach (var word in missingWords)
            {
                txtOutput.AppendText(string.Format("{0},\n", word));
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Hide();
            Close();
        }

        private void lbFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowMissingWords();
        }
    }

}
